package com.treeroot.designMode.Factory;

public class Controller {

    private  final  CakeFactory cakeFactory;

    public Controller(CakeFactory cakeFactory) {
        this.cakeFactory = cakeFactory;
    }

    public void run() {
        // 使用工厂创建蛋糕
        Cake cake = cakeFactory.createCake();
        cake.produce();
    }

    public static void main(String[] args) {
            // 创建苹果蛋糕工厂
            CakeFactory appleCakeFactory = new AppleCakeFactory();
            // 创建苹果蛋糕控制器
            Controller appleCakeController = new Controller(appleCakeFactory);
            // 运行苹果蛋糕控制器
            appleCakeController.run();
            // 创建香蕉蛋糕工厂
            CakeFactory bananaCakeFactory = new BananaCakeFactory();
            // 创建香蕉蛋糕控制器
            Controller bananaCakeController = new Controller(bananaCakeFactory);
            // 运行香蕉蛋糕控制器
            bananaCakeController.run();
    }
}
